﻿<cfsilent>
	<cfscript>

		sessionAdvice = getProperty("serviceFactory").getBean("sessionAdvice");
		dictAdvice = getProperty("serviceFactory").getBean("senateDictionaryAdvice");
		datetimeAdvice = getProperty("serviceFactory").getBean("datetimeAdvice");
		
		markAdvice = getProperty("serviceFactory").getBean("markAdvice");

		teacherId = sessionAdvice.getAutherUserID();
		
		hashCode = event.getArg("Sign");
		taskId = event.getArg("TSK");
		taskType = event.getArg("TT");

		checked = false;
		
		try{
			
			if ( decrypt(hashCode, teacherId, "PBEWithMD5AndDES", "Hex") eq taskId ) {
				
				/* 载入补考教学任务 */
				
				sql = "SELECT 
							task_prog, mark_need, mark_done 
						FROM 
							t_resitplan 
						WHERE 
							task_id = :taskId";
							
				queryObj = new query( datasource=application.dnsSlave );
				
				queryObj.addParam( name="taskId", value=taskId, cfsqltype="cf_sql_varchar" );
				
				rs_task = queryObj.execute( sql=sql ).getResult();
				
				
				if ( rs_task.task_prog eq "2" or rs_task.task_prog eq "3" ) {
					
					checked = true;
					
					transaction {
						
						/* 更新成绩提交状态为 3 已提交 */
						sql = "UPDATE t_resitplan SET task_prog = '3' WHERE task_id = :taskId ";
									
						queryObj = new query( datasource=application.dnsMaster );
						
						queryObj.addParam( name="taskId", value=taskId, cfsqltype="cf_sql_varchar" );
						
						queryObj.execute( sql=sql );
						
						
						/* 转置成绩到正式成绩记录 */
						sql = "SELECT 
									mark_resit, mark_renote,
									mark_limite, scc_id 
								FROM 
									t_temp_mark_resit 
								WHERE 
									task_id = :taskId 
								ORDER BY 
									stu_id";
									
						queryObj = new query( datasource=application.dnsMaster );
						
						queryObj.addParam( name="taskId", value=taskId, cfsqltype="cf_sql_varchar" );
						
						rs_mark = queryObj.execute( sql=sql ).getResult();
		
						timeStamp = datetimeAdvice.getCurrentDatetimeString();
						
						
						for ( row=1 ;row LTE rs_mark.recordCount; row++ ) {
							
							sql = "SELECT 
										t_student_mark.mark_renote, 
										t_student_mark.mark_note,
										t_student_mark.mark_mode, 
										t_student_mark.mark_resit, 
										t_student_mark.mark_result, 
										t_course.course_credit, 
										credit_point  
									FROM 
										t_student_mark 
										INNER JOIN t_course ON t_course.cid = t_student_mark.cid 
									WHERE 
										scc_id = :sccId ";
										
							queryObj = new query( datasource=application.dnsMaster );
							
							queryObj.addParam( name="sccId", value=rs_mark["scc_id"][row], cfsqltype="cf_sql_varchar");
							
							rs_studentMark = queryObj.execute( sql=sql ).getResult();
							
							
							if ( rs_studentMark.recordCount GT 0 ) {
																
								/* 根据备注规范 */
								
								markResit = rs_mark["mark_resit"][row];
							
								/* 2 - 缺考 */
								if ( rs_studentMark.mark_renote eq "2" ) {
									markResit = -1;
								}
							
								/* 9 - 违纪 */
								if ( rs_studentMark.mark_renote eq "9" ) {
									markResit = -1;
								}
								
								/*学分*/
								courseCredit = rs_studentMark.course_credit;
								
								if( markResit lt 60 AND rs_studentMark.mark_result lt 60){
									courseCredit = 0;	
								}
								
								/*绩点*/
								theCreditPoint = markAdvice.getMarkCredit( rs_studentMark.mark_mode, rs_studentMark.course_credit, rs_studentMark.mark_result, markResit, rs_mark["mark_limite"][row]); /*更新绩点*/
								
								sql = "UPDATE
											t_student_mark
										SET
											mark_resit = :markResit,
											mark_renote = :markReNote,
											mark_resit_time = :markResitTime,
											mark_resit_limit = :markResitLimit,
											tch_id = :tchId, 
											credit = :credit, 
											credit_point = :theCreditPoint,
											credit_point_o = :creditPointO  
										WHERE 
											scc_id = :sccId ";
											
								queryObj = new query( datasource=application.dnsMaster );
								
								queryObj.addParam( name="markReNote", value=rs_mark["mark_renote"][row], cfsqltype="cf_sql_char" );
								queryObj.addParam( name="markResitTime", value=timeStamp, cfsqltype="cf_sql_char" );
								queryObj.addParam( name="markResitLimit", value=rs_mark["mark_limite"][row], cfsqltype="cf_sql_decimal", scale = 2 );
								queryObj.addParam( name="tchId", value=teacherId, cfsqltype="cf_sql_varchar" );
								queryObj.addParam( name="sccId", value=rs_mark["scc_id"][row], cfsqltype="cf_sql_varchar" );
								queryObj.addParam( name="markResit", value=markResit, cfsqltype="cf_sql_decimal", scale = 2  );
								queryObj.addParam(name="credit", value=courseCredit, cfsqltype="cf_sql_integer");
								queryObj.addParam( name="theCreditPoint", value=theCreditPoint, cfsqltype="cf_sql_decimal", scale=4 );
								queryObj.addParam(name="creditPointO", value=courseCredit * theCreditPoint, cfsqltype="cf_sql_varchar");
								
								queryObj.execute( sql=sql );
								
							}
								
						}
						
						/* 删除临时成绩记录 */
						
						
						for ( row=1; row LTE rs_mark.recordCount; row++ ) {
							
							sql = "DELETE FROM 
										t_temp_mark_resit 
									WHERE
										scc_id = :sccId";
										
							queryObj = new query( datasource=application.dnsMaster );
							
							queryObj.addParam( name="sccId", value=rs_mark["scc_id"][row], cfsqltype="cf_sql_varchar" );
							
							queryObj.execute( sql=sql );
							
						}
						
					}
					
					/* 读取正式成绩库 生成分析报告 */
					targetArgs = structNew();
					structInsert( targetArgs, "TSK", taskId, true );
					structInsert( targetArgs, "TT", taskType, true );
					structInsert( targetArgs, "Sign", encrypt(taskId, teacherId, "PBEWithMD5AndDES", "Hex"), true );

				}

			}
		}
		catch (any ecpt) {
		}
		
		/* 判断当前显示课表内容 */
		currentTab = event.getArg("TabID", "labNotice");
	
	</cfscript>
</cfsilent>
						
<cfif checked >
		
		<div class="UItab">
			<div class="tabLables">
				<span <cfif currentTab eq "labNotice">class="active"</cfif> id="labNotice" tabTarget="Notice">网上成绩提交</span>
			</div>
		</div>
		<script language="javascript" type="text/javascript">
			//<![CDATA[
			<!--
			$(document).ready(function() {
						
				/* init Tab */
				$("div.tabContent").hide();
				$("div#" + $("div.tabLables span.active").attr("tabTarget")).show();
				
				$("div.tabLables > span").click(function(){
					var $targetID = $(this).attr("tabTarget");
						
					$("div.tabLables span").removeClass("active");
					$(this).addClass("active");
							
					$("div.tabContent").not('[id="' + $targetID + '"]').hide();
					$("div.tabContent#" + $targetID).show();
				});
						
			});
			// -->
			//]]>
		</script>
		
		<div id="Notice" class="tabContent">
		
			<div class="noticeBlock">
				
				<div class="operation">
					<a class="uiButton" target="_blank" href="<cfoutput>#buildURL('taskMarkResitPrint', targetArgs)#</cfoutput>"><i class="mrs img btnPrint"></i><span class="uiButtonText">打印成绩单</span></a>
				</div>
							
				<h3>补考成绩已提交</h3>
				<p>
					<span class="img icon16x16 message"></span>
					感谢您完成课程补考成绩的网上提交工作. 如您还有其他教学任务需提交补考成绩, <a href="<cfoutput>#buildURL('taskMarkResit')#</cfoutput>">提交其他任务成绩</a>.
				</p>
				<hr/>
			</div>
		
			<div class="systemNotice">
				<h3><span class="img icon16x16 info"></span>打印成绩单</h3>
				<p>
					请打印课程成绩归档记录单, 签字后交回开课学院存档. 
				</p>
				<form id="formRemove" class="formWrapper Transparent" method="post" action="<cfoutput>#buildURL('taskMarkResitPrint')#</cfoutput>" target="_blank">
					<input type="hidden" name="TSK" value="<cfoutput>#taskId#</cfoutput>" />
					<input type="hidden" name="TT" value="<cfoutput>#taskType#</cfoutput>" />
					<input type="hidden" name="Sign" value="<cfoutput>#encrypt(taskId, teacherId, 'PBEWithMD5AndDES', 'Hex')#</cfoutput>" />
					<div class="lable"><input class="button2" type="submit" value="打印成绩单" /></div>
				</form>
				
			</div>
		
		</div>
		
	<cfelse>
	
		<div class="systemNotice">
			<h3><span class="img icon16x16 message"></span>错误的参数</h3>
			<p>请关闭浏览器重新登录 或 检查您是否使用了正确访问方式</p>
		</div>
		
</cfif>						
						
						
						